#include <stdio.h>

void swap(int *x, int *y) {
    int tmp = *x;

    *x = *y;
    *y = tmp;
}

void printArray(int *a, int num) {
    int *p = a;

    for (int i=0; i<num; i++) {
        printf("p+i=%p, a+i=%p\n", p+i, a+i);
        printf(
            "*(p+i)=%d, *(a+i)=%d, p[i]=%d, i[p]=%d, i[a]=%d\n",
            *(p+i), *(a+i), p[i], i[p], i[a]
            );
    }
}

void main(void) {
    char a[][4]={"abcd", "efgh", "aabc"};

    for (int i=0; i<3; ++i) {
        printf("a[%d]:%s\n", i, a[i]);
    }
    return;
    printf("point a[0]: %p\n", a[0]);

    int b[][3] = {{1,2,3}, {2,3,4}, {3,4,5}};

    char **pa;

    char *pb;

    printf("pa指针的长度:%lu\n",sizeof(pa));
    printf("point pa:%p pb:%p\n", pa, pb);

    pb = a[0];

    //*pa = a[0];

    printf("point pb:%p\n", pb);

    printf("pb:%s\n", pb);

    pa = &pb;

    printf("point pa:%p; point pa[0]:%p; point *pa:%p\n", pa, pa[0], *pa);

    /** 只能输入pa[0] 因为pa[1]找不到地址
    for (int i=0; i<3;++i) {
        printf("pa[%d]:%s\n", i, pa[i]);
    }*/

    char *c1[] = {"abcdd", "defa"};

    pa = c1;

    printf("pa指针的长度:%lu\n",sizeof(pa));
    puts("通过pa指向(char *)指针型数组:");
    for (int i=0; i<2; ++i) {
        printf("pa[%d]:%s\n", i, pa[i]);
    }

    printf("a[0]:%s %p\n", a[0], a[0]);

    pa=0;

    printf("pa指针的长度:%lu\n",sizeof(pa));
    printf("point pa:%p\n", pa);

    //取nil指针的值会报错
    puts("下面报错!");
    printf("point *pa:%p\n", *pa);

    int a1[2][3];

    int **pa1;
    //*pa1 = a1[0];


    return;

    for (int i=0; i<3; ++i) {
        printf("a[%d]:%c\n", i, *pa[i]);
    }
}

